<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>廉政建设责任书编辑页面</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<%@ include file="/module/js.jsp"%>
<%@ include file="/module/orderField.jsp"%>
<script type="text/javascript" src="${basePath}/js/jquery.Huploadify.js"></script>
<link href="${basePath}/css/Huploadify.css" rel="stylesheet">
	<style>
table label.error {
	margin-left: 5px;
	width: auto;
	display: inline;
	color: red;
}

.textat {
	text-align: center;
}
</style>
	<script type="text/javascript">
		//计算两个时间中间的年月
		function getYearAndMonth(staYear, endYear) {
			var result = [];
			while (staYear <= endYear) {
				result.push(staYear);
				staYear++;
			}
			return result;
		}

		//图片上传
		var file_path = "prefix";
		var file_path_one = null;
		var fileMap = new Array();
		$(function() {
			//默认添加当时系统时间的年份，可手动修改，大于等于2010小于等于2099的正整数
			var myDate = new Date();
			var oldYear = '${entity.lzNf}';
			var year = myDate.getFullYear();
			if (oldYear != null && oldYear != '' && oldYear != 0) {
				year = oldYear;
			}
			var arrp = getYearAndMonth('2010', '2099');
			var _options = '';
			for (var i = 0; i < arrp.length; i++) {
				var val = arrp[i];
				if (val == year) {
					_options = _options
							+ "<option selected='selected' value="+val+">"
							+ val + "年</option>";
				} else {
					_options = _options + "<option value="+val+">" + val
							+ "年</option>";
				}

			}
			$("#lzNf").html(_options);

			var up = $('#uploadadd').Huploadify({
				auto : false,
				fileTypeExts : '*.*',
				multi : true,
				formData : {
					key : 123456,
					key2 : 'vvvv'
				},
				fileSizeLimit : 99999999999,
				showUploadedPercent : true,
				showUploadedSize : true,
				removeTimeout : 9999999,
				uploader : '${basePath}/partyIncorrupt/source_upload',
				onUploadStart : function(file) {
					console.log(file.name + '开始上传');
				},
				onInit : function(obj) {
					console.log('初始化');
					console.log(obj);
				},
				onUploadComplete : function(file, data) {
					debugger;
					var fi = $.parseJSON(data);
					//文件名称
					var filename = fi.filename;
					//生成后的文件名
					var sysFilepath = fi.sysfilepath;
					//文件路径
					var filepath = fi.filepath;
					file_path_one = filename + "," + filepath;
					file_path = file_path + "|" + filepath;
					up.filePath = file_path_one;
					//保存到集合
					fileMap[file.index] = new Array(file_path_one);
				},
				onCancel : function(file) {
					console.log(file.name + '删除成功');
				},
				onClearQueue : function(queueItemCount) {
					console.log('有' + queueItemCount + '个文件被删除了');
				},
				onDestroy : function() {
					console.log('destroyed!');
				},
				onSelect : function(file) {
					console.log(file.name + '加入上传队列');
				},
				onQueueComplete : function(queueData) {
					console.log('队列中的文件全部上传完成', queueData);
				}
			});
		});

		//删除图片
		function deletefile(id) {
			var url = "${basePath}/partyIncorrupt/deletefile";
			$.ajax({
				type : "POST",
				url : url,
				dataType : "json",
				data : {
					filepath : id
				},
				success : function(data) {
					if (data.success == "0000") {
						alert("删除数据成功！");
						var file_name = id.split(",")[0];
						$("#" + file_name + "_hr").parent().parent().remove();
					} else {
						alert("未写入数据库的文件没有删除！请联系管理员！");
					}
				}
			})
		}
	</script>

	<script>
		$(document).ready(function() {
			
			var lzFw = '${entity.lzFw}';
			if(lzFw == '自定义'){
				showTR(1);
				$("#zdyRy").attr("value",'${zdyRy }');
			}

			$("#div1").dialog({
				width : 'auto',
				height : 'auto',
				bgiframe : true,
				modal : true,
				draggable : true,
				resizable : false,
				title : '选择职工党员',
				autoOpen : false,
				buttons : {
					'取消' : function() {
						$(this).dialog('close');
					},
					'确定' : function() {

						  var data = [];
                          var selected_item = document.getElementById("toSelect1");
                   
                          if(selected_item.length==null || selected_item.length==0){
                              alert("请选择一项");
                              return false;
                          }
                          
						var wyxm_id = $("#toSelect1 option").map(function() {
							return $(this).val();
						}).get().join(",")
						var wyxm_name = $("#toSelect1 option").map(function() {
							return $(this).text();
						}).get().join(",")
						$("#zdyRy").val(wyxm_name);
						$("#zdyRy_id").val(wyxm_id);
						$(this).dialog('close');
					}

				}
			});

		});
		function showdiv() {
			$('#div1').dialog('open');
		}

		function showTR(type) {
			if (type == 1) {
				$('#trp').show();
			} else {
				$('#trp').hide();
			}

		}
	</script>
</head>
<body>
	<form action="#" name="Form" id="Form" method="post">
		<input type="hidden" id="lzId" name="lzId" value="${entity.lzId }" />
		<input type="hidden" id="urlTp" name="urlTp" value="" />
		<table cellpadding="0" cellspacing="0" border="0" class="table-border"
			width="95%">
			<tr>
				<td class="table-header" colspan="4">廉政建设责任书</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%"><font
					style="color: red;">*</font>年份：</td>
				<td class="table-contentTD" style="width:35%;"><select id="lzNf" name="lzNf"
					class="selectList">
				</select></td>

				<td class="table-titleTD"><font style="color: red;">*</font>责任书名称：</td>
				<td class="table-contentTD"><input id="zrsMc" name="zrsMc"
					placeholder="责任书名称" autocomplete="off" maxlength="100"
					class="inputText required" value="${entity. zrsMc}" /></td>
			</tr>

			<tr>
				<td class="table-titleTD"><font style="color: red;">*</font>范围：</td>
				<td class="table-contentTD" colspan="3"><input type="radio"
					value="党总支委员" name="lzFw"
					<c:if test="${entity.lzFw=='党总支委员'  || entity.lzId==0 }">checked="checked"</c:if>
					onclick="showTR(0)" />党总支委员 <input type="radio" value="党支部书记"
					name="lzFw"
					<c:if test="${entity.lzFw=='党支部书记' }">checked="checked"</c:if>
					onclick="showTR(0)" />党支部书记 <input type="radio" value="自定义"
					name="lzFw"
					<c:if test="${entity.lzFw=='自定义' }">checked="checked"</c:if>
					onclick="showTR(1)" />自定义</td>
			</tr>

			<tr id="trp" style="display: none">
				<td class="table-titleTD"><font style="color: red;">*</font>自定义人员： </td>
				<td class="table-contentTD" colspan="3"><input type="text"
					id="zdyRy" name="zdyRy" value="" readonly="readonly"
					placeholder="选择" maxlength="100" class="inputText"  value="${zdyRy }"/>&nbsp&nbsp;
					<input type="hidden" id="zdyRy_id" name="zdyRy_id"
					value="${zdyRy_id }" /> <input type="button" id="optionBtn"
					value="选择" class="inputButton" onclick="javascript:showdiv();"
					placeholder="请选择" /></td>
			</tr>

			<c:if test="${ entity.lzId != 0  }">
				<tr>
					<td class="table-titleTD">创建人：</td>
					<td class="table-contentTD">${entity.creatorName}</td>
					<td class="table-titleTD">创建日期：</td>
					<td class="table-contentTD">${entity.createTime}</td>
				</tr>
			</c:if>
			<tr>
				<td class="table-titleTD">附件：</td>
				<td class="table-contentTD" colspan="3">
					<table>
						<tr>
							<td colspan="2">
								<div id="uploadadd"></div>
							</td>
						</tr>
						<c:if test="${fn:length(dataList) > 0}">
							<c:forEach items="${dataList}" var="datalist" varStatus="index">
								<tr>
									<td>[文件] ${datalist.fileName}</td>
									<td><a
										href="${basePath}/DownLoadFileServlet?filename=${datalist.fileName}&filepath=${datalist.filePath}">下载</a>

										<%-- <button type="button"  onclick="window.location.href='${basePath}/DownLoadFileServlet?filename=${datalist.fileName}&filepath=${datalist.filePath}'">下载</button> --%>
										&nbsp;&nbsp;

										<button id="${datalist.fileId}_hr" type="button"
											onclick="deleteByPK('${datalist.fileId}','${datalist.filePath}');">删除</button>
									</td>
								</tr>
							</c:forEach>
						</c:if>
					</table>
				</td>
			</tr>
			<tr>
				<td class="table-titleTD">备注：</td>
				<td class="table-contentTD" colspan="3"><textarea rows="15"
						cols="60" name="remark" id="remark" maxlength="2000">${entity.remark }</textarea>
				</td>
			</tr>

		</table>
	</form>




	<div id="div1" style="display: none;">
		<table cellpadding="0" cellspacing="0" border="0" class="table-border">
			<tr>
				<td style="clear: both; width: 45%"><input class="text"
					name="searchemp"
					ondblclick="javascript:filterSelectItems('sourseFromSelect1','fromSelect1','toSelect1',this.value);"
					onkeyup="javascript:filterSelectItems('sourseFromSelect1','fromSelect1','toSelect1',this.value);" /><font
					color="green">在此查找</font> <br /> <br /> <label
					style="color: red;">未选中:</label><br /> 
					
					<select name="fromSelect1"
						id="fromSelect1" multiple="multiple"
						style="width: 400px; height: 300px;"
						ondblclick="moveField('fromSelect1','toSelect1');">
						<c:forEach items="${partyLeagueMember}" var="data">
							<option value="${data.dYID}">${data.xM}</option>
						</c:forEach>
				</select> 
				
				<select name="sourseFromSelect1" id="sourseFromSelect1"
					multiple="multiple"
					style="width: 400px; height: 300px; display: none;"
					ondblclick="moveField('fromSelect1','toSelect1');">
					
					<c:choose>
							<c:when test="${ entity.lzId == 0  }">
									<c:forEach items="${partyLeagueMember}" var="data">
										<option value="${data.dYID}">${data.xM}</option>
									</c:forEach>
							</c:when>
							<c:otherwise>
								<c:forEach items="${plist}" var="data2">
									<c:forEach items="${partyLeagueMember}" var="data">
										<c:choose>
											<c:when test="${data2.dyId == data.dYID }">
											</c:when>
											<c:otherwise>
												<option value="${data.dYID}">${data.xM}</option>
											</c:otherwise>
										</c:choose>
									</c:forEach>
								</c:forEach>
							</c:otherwise>
					</c:choose>
					
						
				</select></td>
				<td align="center" style="width: 10%"><input type="button"
					onclick="moveAllField('fromSelect1','toSelect1');"
					style="width: 50px;" value=">>" /> <br> <br /> <input
						type="button" onclick="moveField('fromSelect1','toSelect1');"
						style="width: 50px;" value=">" /> <br /> <br /> <input
						type="button" style="width: 50px;" value="&lt"
						onclick="moveField('toSelect1','fromSelect1');" /><br /> <br />
						<input type="button" style="width: 50px;"
						onclick="moveAllField('toSelect1','fromSelect1');" value="&lt&lt" /></td>
				<td style="width: 45%"><br /> <label style="color: red;">已选中:</label><br />
					
					<select name="toSelect1" id="toSelect1" multiple="multiple"
					class="text" style="width: 400px; height: 300px;"
					ondblclick="moveField('toSelect1','fromSelect1');">
						<c:forEach items="${plist}" var="data2">
							<option value="${data2.dyId}">${data2.dyXm}</option>
						</c:forEach>
				</select>
				</td>
			</tr>
		</table>
	</div>

	<br />

	<c:choose>
		<c:when test="${ entity.lzId == 0 }">
			<table cellpadding="1" cellspacing="1" border="0" align="left">
				<tr>
					<%-- <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId("ZHDJ_DJZX_DJZX")%>" key="add"> --%>
					<td><input type="button" id="btnSave2Info" class="inputButton"
						style="text-align: center;" value="保存" /></td>
					<td><input type="button" id="btnSave2AddInint"
						class="inputButton" style="text-align: center;" value="保存并新增" /></td>
					<%-- </kl:permission> --%>
					<td><input type="button" id="Cancel1" class="inputButton"
						style="text-align: center;" value="取消" onclick="cancle()" /></td>
					<td><input type="button" id="returnBut1" class="inputButton"
						value="返回" style="text-align: center;" onclick="back2Index()" /></td>
				</tr>
			</table>
		</c:when>
		<c:otherwise>
			<table cellpadding="1" cellspacing="1" border="0" align="left">
				<tr>
					<%-- <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId("ZHDJ_DJZX_DJZX")%>" key="modify"> --%>
					<td><input type="button" id="btnSave2Index"
						class="inputButton" style="text-align: center;" value="保存" /></td>
					<%-- </kl:permission> --%>
					<td><input type="button" id="Cancel2" class="inputButton"
						style="text-align: center;" value="取消" onclick="cancle()" /></td>
					<td><input type="button" id="returnBut2" class="inputButton"
						value="返回" style="text-align: center;" onclick="back2Index()" /></td>
				</tr>
			</table>
		</c:otherwise>
	</c:choose>

	<script>
		$(document).ready(function() {

			//保存成功返回详情页面
			$("#btnSave2Info").click(function() {
				var lzFw =$("input[name='lzFw']:checked").val();
				
				if(lzFw == '自定义'){
					$("#zdyRy").addClass("required");
				}else{
					$("#zdyRy").removeClass("required");
				}
				
				var _form = $("#Form").validate();
				if (_form.form()) {
					$("#urlTp").attr("value", 1);
					document.Form.action = "${basePath}/partyIncorrupt/save";
					document.Form.submit();
				}
			});

			//保存成功继续增加页面
			$("#btnSave2AddInint").click(function() {
				var lzFw =$("input[name='lzFw']:checked").val();
				if(lzFw == '自定义'){
					$("#zdyRy").addClass("required");
				}else{
					$("#zdyRy").removeClass("required");
				}
				
				var _form = $("#Form").validate();
				if (_form.form()) {
					$("#urlTp").attr("value", 2);
					document.Form.action = "${basePath}/partyIncorrupt/save";
					document.Form.submit();
				}
			});

			//保存成功返回列表页面
			$("#btnSave2Index").click(function() {
				var lzFw =$("input[name='lzFw']:checked").val();
				if(lzFw == '自定义'){
					$("#zdyRy").addClass("required");
				}else{
					$("#zdyRy").removeClass("required");
				}
				
				var _form = $("#Form").validate();
				if (_form.form()) {
					$("#urlTp").attr("value", 3);
					document.Form.action = "${basePath}/partyIncorrupt/save";
					document.Form.submit();
				}
			});

		});

		//取消->当前页面刷新
		function cancle() {
			window.location.reload();//刷新当前页面.
		}

		//返回列表页面
		function back2Index() {
			window.location.href = '${basePath}/partyIncorrupt/index';
		}

		//已有的数据进行删除操作
		function deleteByPK(id, filePath) {
			var action = "${basePath}/partyIncorrupt/source_upload_update";
			layer.confirm("您是否删除当前选中数据信息", {
				icon : 3,
				title : '提示',
				skin : 'layer-ext-moon'
			}, function(index) {
				$.ajax({
					type : "POST",
					url : action,
					//dataType:"json",
					data : {
						fileId : id,
						filePath : filePath
					},
					success : function(data) {
						if (data.success == "0000") {
							layer.alert('删除数据成功', {
								icon : 6
							});
							$("#" + id + "_hr").parent().parent().remove();
						} else {
							layer.alert('未写入数据库的文件没有删除！请联系管理员！', {
								icon : 5
							});
						}
					}
				})
			}, function(index) {
				layer.close(index);
			});
		}

		if ("${msg}" != "") {
			layer.alert("${msg}", {
				icon : 6
			});
		}
		//compareListValue(document.getElementById('mz'),'${student.mz}');
	</script>
</body>
</html>